<template>
  <div
    class="task-finish-item"
    v-if="taskData"
  >
    <div class="task-finish-item-left">
      <img
        :src="taskData.createUser.avatar"
        class="avadar"
        v-if="taskData.createUser.avatar"
      />
    </div>
    <div class="task-finish-item-right">
      <div
        class="task-top"
        @click="toDetail"
      >
        <div class="task-creator">
          <h3>{{taskData.createUser.userName}}<span>{{taskData.createUser.opDepartmentName}}</span></h3>
          <div>
            <span>{{TaskType}}</span>
            <van-rate
              v-if="important_level>0"
              v-model="important_level"
              :size="14"
              color="#FDAA01"
              void-icon="star"
              void-color="#ffffff"
            />
          </div>
        </div>
        <div class="task-status">
          <span
            class="task-status-text"
            v-if="pjType == 1"
          >{{Ac_status}}</span>
          <span v-if="colorTag">
            <van-tag
              :color="colorTag.color"
              :text-color="colorTag.textcolor"
              class="important-tag"
            >{{ UrgentLevel }}</van-tag>
          </span>
        </div>
      </div>
      <!-- <span
        class="task-receive-time"
        v-if="pjType==3"
      >{{Ac_statusForTime(taskData)}}</span> -->
      <div class="task-content">
        <MyContext2
          :t="taskData.content"
          :styleType="commentStyle"
        ></MyContext2>
        <div v-if="taskData.taskResourceList.length > 0">
          <MyImgs :imgData='taskData.taskResourceList'></MyImgs>
        </div>
        <span class="task-receive-time">{{Ac_statusForTime(taskData)}}</span>
      </div>
      <!-- 进度 -->
      <div
        class="head"
        v-if="pjType == 3 && taskData.taskAcceptList.length>0"
      >
        <p>
          <font
            v-for="acceptUser in taskData.taskAcceptList"
            :key="acceptUser"
          >
            {{ acceptUser.userName }},</font>
          <font style="color: #999">{{ taskData.taskAcceptList.length }}人已接单</font>
        </p>
      </div>
      <template v-if="pjType != 3">
        <div
          v-for="item in taskData.taskAcceptList"
          :key="item"
        >
          <!-- <div class="task-receive-time" v-if="pjType != 2 && pjType != 3 ">{{Ac_statusForTime(item)}}</div> -->
          <div class="task-remark">
            <fold-text
              v-if='item.remark'
              :content="item.remark"
            ></fold-text>
          </div>
          <div
            class="task-submit"
            v-if="showType == true && item.ac_adopt_status === 1 && pjType !=1"
          >
            <img
              v-if="pjType != 2"
              src="@/assets/images/seal-finish.png"
              class="icon-seal"
            />
            <p class="task-submit-text"><a>{{item.userName}}</a>:{{item.ac_finish_remak}}</p>
            <MyImgs
              v-if="item.taskacceptResourceList"
              :imgData='item.taskacceptResourceList'
            ></MyImgs>
          </div>
          <!-- <div class="task-finish-time">
            <span>05-12完成，耗时1天</span>
          </div> -->
        </div>
      </template>
    </div>
  </div>
</template>

<script>
import { Button, Rate, tag } from "vant";
import FoldText from "@/components/foldText";
import maps from "@/util/maps";
import MyImgs from "@/components/task/Imgs.vue";
import MyContext2 from "@/components/task/context2.vue";
export default {
  name: "task-finish-item",
  components: {
    [Button.name]: Button,
    [Rate.name]: Rate,
    [tag.name]: tag,
    FoldText,
    MyContext2,
    MyImgs
  },
  /**
   * taskData:任務數據
   * pjType：展示不同的字段 :2：我發的任務詳情，1：我接的任務 0 大廳 3：我發的任務列表
   * showType true and false
   */
  props: {
    taskData: Object,
    pjType: String,
    showType: Boolean
  },
  data() {
    return {
      colorTag: {},
      important_level: 0,
      user:{}
    };
  },
  computed: {
    TaskType() {
      let text = "";
      const taskAcceptList = this.taskData.taskAcceptList;
      if(taskAcceptList&&taskAcceptList.length>0){
        taskAcceptList.forEach(e=>{
          if(e.ac_user_id === this.user.id){
            this.important_level = e.important_level;
            text = maps.taskTypeMap[e.task_type];
          }
        })
      }
      return text || "";
    },
    Ac_status() {
      let status = "";
      switch (this.pjType) {
        case "2": //我发的任务
          status = this.taskData.status == 0 ? "开放中" : "已关闭";
          break;

        default:
          status = this.taskData.taskAcceptList[0]
            ? maps.statusMap[this.taskData.taskAcceptList[0].ac_status]
            : "未接单";
          break;
      }
      return status;
    },
    // 根据订单状态显示状态与时间
    Ac_statusForTime() {
      return item => {
        return maps.getTimer(item);
      };
    },
    UrgentLevel() {
      return maps.urgentLevelMap[this.taskData.urgentLevel];
    }
  },
  mounted() {
    this.user = JSON.parse(localStorage.getItem('user'));
    console.log("3433333",this.taskData);
    const taskAcceptList = this.taskData.taskAcceptList;
      if(taskAcceptList&&taskAcceptList.length>0){
        taskAcceptList.forEach(e=>{
          if(e.ac_user_id === this.user.id){
            this.important_level = e.important_level;
          }
        })
      }
    this.colorTag = maps.urgentLevelColorMap[this.taskData.urgentLevel];
  },
  watch:{
    taskData(val){
      console.log("1111111111111111111111111111111111",this.taskData);
      const taskAcceptList = val.taskAcceptList;
      if(taskAcceptList&&taskAcceptList.length>0){
        taskAcceptList.forEach(e=>{
          if(e.ac_user_id === this.user.id){
            this.important_level = e.important_level;
          }
        })
      }
    }
  },
  methods: {
    toDetail() {
      let data = {
        taskId: this.taskData.id,
        myTaskId: this.taskData.taskAcceptList[0]
          ? this.taskData.taskAcceptList[0].ac_id
          : null,
        taskStatus: this.taskData.taskAcceptList[0]
          ? this.taskData.status
          : null,
        taskAcceptStatus: this.taskData.taskAcceptList[0]
          ? this.taskData.taskAcceptList[0].ac_status
          : null
      };
      this.$emit("to-detail", data);
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
.task-finish-item {
  background: #fff;
  padding: 30px 20px 0 20px;
  display: flex;
  &-left {
    width: 80px;
    margin-right: 20px;
    .avadar {
      width: 80px;
      height: 80px;
      border-radius: 8px;
    }
  }
  &-right {
    flex-grow: 1;
    text-align: left;
    padding-bottom: 20px;
  }
  .head {
    background: #f7f7f7;
    padding: 20px;
    font-size: 26px;
    color: #576b95;
    margin-bottom: 20px;
  }
}

.task-top {
  display: flex;
  justify-content: space-between;
  .task-creator {
    text-align: left;
    h3 {
      font-size: 32px;
      color: #333;
      line-height: 1.2;
      margin-bottom: 10px;
      span {
        font-size: 24px;
        color: #999;
        margin-left: 20px;
        font-weight: normal;
      }
    }
    div {
      display: flex;
      align-items: center;
      span {
        font-size: 24px;
        color: #999;
        margin-right: 20px;
      }
    }
  }
  .task-status {
    text-align: right;
    &-text {
      display: block;
      font-size: 26px;
      color: #00b500;
      margin-bottom: 14px;
    }
    &-type {
      display: inline-block;
      font-size: 22px;
      color: #ec407a;
      background: #fbdce6;
      padding: 2px 8px;
      height: 34px;
      text-align: center;
      line-height: 34px;
      background: #fbdce6;
      border-radius: 4px;
    }
  }
}

.task-content {
  padding: 20px 0;
  &-text {
    font-size: 30px;
    text-align: left;
  }
  .task-content-text {
    padding-bottom: 30px;
  }
}

.task-receive-time {
  font-size: 24px;
  color: #999;
  margin-top: 20px;
}
.task-remark {
  margin-top: 20px;
  width: 600px;
}
.task-submit {
  background: #f7f7f7;
  padding: 20px;
  position: relative;
  margin-top: 20px;
  .icon-seal {
    z-index: 2;
    position: absolute;
    right: 0;
    top: 0;
    width: 108px;
    height: 108px;
  }
  &-text {
    font-size: 28px;
    color: #333;
    a {
      color: #576b95;
    }
  }
  &-picture {
    margin-top: 30px;
    display: flex;
    &-item {
      width: 160px;
      height: 160px;
      margin-right: 16px;
      background: #fff;
      position: relative;
      img {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        max-width: 100%;
        max-height: 100%;
      }
    }
  }
}
.task-finish-time {
  font-size: 24px;
  color: #999;
  margin-top: 20px;
  display: flex;
}
</style>
